package com.qf.consumer;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.qf.vo.EmailVo;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class EmailConsumer {

    @RabbitListener(queues = "email-queue")
    public void getEamil(EmailVo emailVo){

        System.out.println(emailVo);

        String title = emailVo.getTitle();
        String to = emailVo.getTo();
        String content = emailVo.getContent();

        // 借助hutool实现邮件发送
        // 根据自己的发件箱配置如下信息
        MailAccount account = new MailAccount();
        account.setHost("smtp.qq.com");
        account.setPort(587);
        account.setAuth(true);
        account.setFrom("212135374@qq.com");
        account.setUser("212135374");
        account.setPass("mwvnuoqofnzgbhjc");

        MailUtil.send(account, CollUtil.newArrayList(to), title, content, false);

    }

}
